package mytest;

import com.xyd.entity.ColBean;
import com.xyd.entity.Computer;
import com.xyd.entity.User;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.List;

public class SpringDemo {

    ClassPathXmlApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");

    @Test
    public void test1() {
        ApplicationContext factory = new ClassPathXmlApplicationContext("spring.xml");
//        System.out.println(factory.containsBean("user1"));
        User user = factory.getBean("user", User.class);
        user.setName("zhangsan");
        user.setPwd("123");

        System.out.println(user.intro());
        ac.destroy();

    }


    @Test
    public void test2() {
        Computer computer = ac.getBean("computer", Computer.class);
        computer.printComputerInfo();
    }


    @Test
    public void test3() {
        ColBean colBean = ac.getBean("listBean", ColBean.class);
        List<String> list = colBean.getList();

        for (String str :
                list) {
            System.out.println(str);
        }
    }
}
